package com.kgc.app.service.impl;

import com.kgc.app.mapper.DevUserMapper;
import com.kgc.app.pojo.DevUser;
import com.kgc.app.pojo.DevUserExample;
import com.kgc.app.service.DevUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DevUserServiceImpl implements DevUserService {

    @Autowired
    private DevUserMapper devUserMapper;

    @Override
    public DevUser loginDevUser(String devCode, String devPassword) {

        //1.创建一个条件对象
        DevUserExample devUserExample = new DevUserExample();
        DevUserExample.Criteria criteria = devUserExample.createCriteria();

        //2.拼接条件
        //先排除错误情况  用户输入错误
        if (null == devCode || devCode.equals("")){
            return null;
        }
        if (null == devPassword || devPassword.equals("")){
            return null;
        }

        criteria.andDevCodeEqualTo(devCode);
        criteria.andDevPasswordEqualTo(devPassword);

        //3.执行查询
        List<DevUser> devUsers = devUserMapper.selectByExample(devUserExample);
        //如果用户名或者密码错误
        if (null ==devUsers || devUsers.size() == 0){
            return  null;
        }

        //把查询到的用户返回
        return devUsers.get(0);
    }
}
